############################################################
# auther	: sgxiao
# Date		: 2009-01-15
# version	: 0.3
# history
#	sgxiao	0.3	remove the @files loop, add ARGV[0]	
#	sgxiao	0.2	modfiy the loop for get the last month's last day information
#	sgxiao	0.1	deal with a single .result file
#############################################################
#!/usr/bin/perl

my @years = qw/ 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 /;
my @months = qw/ 01 02 03 04 05 06 07 08 09 10 11 12 /;

#my @files = qw/ 1_50 1_150 1_200 2_200 5_150 10_200 /;

#foreach $file (@files) {

#print $file, "\n";
my $file = $ARGV[0];
####
$C = 1;
$G = 1;
$F = 1;
my $last_close_price = 0.0;

foreach $year (@years) {

my $last_day = 0;
my $last_value = 0;
#my $last_close_price;
#my $last_return_m = 0.0;


###
foreach $month (@months) {
##
open CONFIG, "$ARGV[1].$file.$year.$month.result";

my $first_day = 0;
my $first_value = 0;
my $first_close_price;

my $return_m = 1;
my $return_s = 1;


$day = 0;
while(<CONFIG>) {
	chomp;
	@array = split /\t/, $_;
	($date, $right_price ,$value) = @array;
	#printf("%s %.15f\n", $date , $value);
	if( $day == 0 ) { ##???
		$first_day = $date;
		$first_close_price = $right_price;
		$first_value = $value;
	}

	#printf("%.15f\n", $return_m);
	if( $value != 0.0 ) {
		$return_m = ($value + 1) * $return_m;
		#$return_m = $return_m - 1;
		#printf("return_m %.15f\n", $return_m);
	}
	$day++;
}

$C = $C * $return_m;

$last_day = $date;

$last_value = $value;

$A = substr($first_day, 0, 6);
$B = $return_m - 1;


$F = ($last_close_price == 0) ? 1 : $right_price / $last_close_price;
$G = $G * $F;

$last_close_price = $right_price;

printf("%s\t%.15f\t%.15f\t%.15f\t%.15f\t%.15f\t%.15f\n", $A, $B, $C - 1, $F - 1, $G - 1, $B + 1 - $F, $C - $G);
#printf("close price %.15f\n", $first_close_price);
#printf("first day %s	value %.15f\n", $first_day, $first_value);
#printf("last day %s	value %.15f\n", $last_day, $last_value);
##
}
###
}
####
#}